// pages/company/company.js
let app =  getApp();

  
Page({
  data: {
    disabled: true,
    btnstate: "default"
  },
  accountBlur: function (e) {
    var content = e.detail.value;
    wx.setStorageSync('content', content);
    if (content != "") {
      this.setData({
        disabled: false,
        btnstate: "primary",
        account: content
      });
    }
  },
  pwdBlur: function (e) {
    var password = e.detail.value;
    wx.setStorageSync('password', password);
    if (password != "") {
      this.setData({
        password: password
      });
    }
  },
  nicknameBlur: function (e) {
    var nickname = e.detail.value;
    wx.setStorageSync('nickname', nickname);
    if (nickname != "") {
      this.setData({
        nickname: nickname
      });
    }
  },
  register: function(){
    wx.request({
      url: `${app.globalData.baseUrl}/user/addUser`, // 目标服务器url
      method: 'POST',
      dataType:'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        username: wx.getStorageSync('content'),
        password: wx.getStorageSync('password'),
        nickname: wx.getStorageSync('nickname')
      },
      success: (res) => {
        let code = res.data.code
        console.log(code);
        if(code === 200){
          wx.reLaunch ({
            url: `../login/login`
          });
        }
      }
    });
  }
});